object Palindrome {
	def main() : Unit = {
		println(new Find().start());
	}
}
 class Find {
  def start() : String = {
  var max : Int;
  var min : Int;
  var x : Int;
  var s : String;
  var random : PseudoRandomNumberGenerator;

  max = 1000;

  min = 0;

  random = new PseudoRandomNumberGenerator().init();

  x = random.getInt(min, max);
  println(x);
  s = new Find().find(x, max);
  return s;
  }
  def find(x : Int, max : Int): String = {
     var y : Int;
      var z : Int;
    y = max/2;
    z = max/2;
    println(y);     
     while((x-y)<1){
       if(y<x){
         println(x);
         println("x is bigger than : "+ y);
         y = y + (z/2);
         z=z/2;
         }else{
            println("x is smaller than : "+ y);
            y = y - (z/2);
              z= z/2;
         }
     }
      return "x found !:"+x;
   }
  }
  //copied from the example given (maze)
  class PseudoRandomNumberGenerator {
    var a : Int;
    var b : Int;
   
    def init() : PseudoRandomNumberGenerator = {
      a = 271828183; // put whatever you like in here
      b = 314159265; 
      return this;
    }
   
    def getInt(min : Int, max : Int) : Int = {
      var posInt : Int;
   
      posInt = this.nextInt();
      if(posInt < 0)
        posInt = 0 - posInt;
   
      return min + (this.mod(posInt, max - min));
    }
   
    def mod(i : Int, j : Int) : Int = { return i - (i / j * j); }
   
    def nextInt() : Int = {
      b = 36969 * ((b * 65536) / 65536) + (b / 65536);
      a = 18000 * ((a * 65536) / 65536) + (a / 65536);
      return (b * 65536) + a;
    }
}
